﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace BZZ.Web.blog.t
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) showInfoList();
          
        }

        protected void showInfoList()
        {
            #region 变量定义
            DataSet dset = new DataSet();
            BZZ.DAL.myTwitter dal = new BZZ.DAL.myTwitter();
            System.Collections.Generic.List<System.Data.SqlClient.SqlParameter> paraList = new List<System.Data.SqlClient.SqlParameter>();
            string dataFields = ""; //读取的字段名，空为所有
            string strWhere = "1=1"; //查询子句
            string strOrderBy = " id desc"; //排序参数，如果需要分页，则必填 
            #endregion


            #region 分页控件绑定
            int pageSize = 30; //分页每页记录个数
            int totalRecourd = 0; //总记录个数
            int currentPage = 1; //当前页码
            try { currentPage = int.Parse(Request.QueryString["p"]); }
            catch { }

            totalRecourd = dal.GetCount(strWhere, paraList);
            dset = dal.GetDatasetByPageSql(currentPage, pageSize, strWhere, strOrderBy, paraList, dataFields);
            if (dset != null && dset.Tables[0].Rows.Count > 0)
            {
                rptInfoList.DataSource = dset;
                rptInfoList.DataBind();
                litPager.Text = LIB.pager.getFrontPager(this, totalRecourd, pageSize);
            }
            
            #endregion
            #region 单页数据绑定
            //strWhere += " " + strOrderBy;
            //dset = dal.GetDataset(strWhere, paraList, dataFields);
            //if (dset.Tables[0].Rows.Count > 0)
            //{
            //    rptInfoList.DataSource = dset;
            //    rptInfoList.DataBind();
            //}
            //else
            //{
            //    litPromptMessage.Text = "没有查询到相关记录";
            //} 
            #endregion

        }


        protected void btnSumit_Click(object sender, EventArgs e)
        {
            #region 获取数据
            string varContent;	//内容
            DateTime varDt;	//日期
            int varStauts;	//状态
            try
            {
                varContent = txtContent.Text.Trim();	//内容
                varDt = DateTime.Now;
                varStauts = 0;// int.Parse(txtStauts.Text.Trim());	//状态
            }
            catch
            {
                LIB.JsWrite.Alert(this, "输入数据格式不合法，请检查输入数据。");
                return;
            }
            #endregion

            #region 赋值model
            BZZ.DAL.myTwitter dal = new BZZ.DAL.myTwitter();
            BZZ.Model.myTwitter model = new BZZ.Model.myTwitter();

                model.content = varContent;	//内容
                model.dt = varDt;	//日期
                model.stauts = varStauts;	//状态
                if (dal.Add(model) > 0)
                {
                    LIB.JsWrite.Alert(this, "添加成功");
                }
                else
                {
                    LIB.JsWrite.AlertAndGoback(this, "操作失败");
                }


            #endregion

        }
    }
}
